﻿@model Himall.Web.Models.ShopModel

@using System.Collections

@{
    ViewBag.Title = "Management";
}

<script src="~/Scripts/jquery.hiMallDatagrid.js"></script>
<script src="~/Scripts/CommonJS.js"></script>

<script type="text/javascript">

    function deleteShopEvent(id) {
        var loading = showLoading();
        ajaxRequest({
            type: 'POST',
            url: './DeleteShop',
            cache: false,
            param: { Id: id },
            dataType: 'json',
            success: function (data) {
                if (data.Successful == true)
                    location.href = './Management';
                loading.close();
            },
            error: function (data) { $.dialog.tips('删除失败,请稍候尝试.'); loading.close(); }
        });
    }

    function businessCategoryShopEvent(id) {

    }

    function Query() {

        var shopName = $("#shopName").val();
        var shopAccount =$("#shopAccount").val();
        var shopGradeId = $("#shopGradeId").val();
        var shopStatus = $("#shopStatus").val();

        $("#shopDatagrid").hiMallDatagrid({
            url: "./List",
            singleSelect: true,
            pagination: true,
            NoDataMsg: '没有找到符合条件的数据',
            idField: "Id",
            pageSize: 15,
            pageNumber: 1,
            queryParams: { "shopName": shopName, "shopAccount": shopAccount, "shopGradeId": shopGradeId, "shopStatus": shopStatus, type: $("#type").val() },
            toolbar: "#shopToolBar",
            columns:
            [[

                { field: "Id", title: "Id", hidden: true },
                { field: "IsSelf", title: "IsSelf", hidden: true },
                {
                    field: "Name", title: "店铺名称", width: 140, formatter: function ( value, row, index )
                    {
                        var id = row.Id.toString();
                        var html = "";
                        if ( row.Status != '被拒绝' )
                        {
                            html = '<a target="_blank" href="/Shop/Home/' + id + '">' + row.Name + '</a>';
                        }
                        else
                        {
                            html = row.Name;
                        }
                        return html;
                    }
                },
                { field: "Account", title: "店铺账号", width: 140 },
                { field: "ShopGrade", title: "等级", width: 140 },
                { field: "EndDate", title: "有效期", width: 140 },
                { field: "Status", title: "状态", width: 140 },
                {
                    field: "operation", operation: true, title: "操作",
                    formatter: function (value, row, index) {
                        var id = row.Id.toString();
                        var html = ['<span class="btn-a">'];

                        if (row.Status == "不可用") {
                            html.push('<a href="./Details?id=' + id + '">查看</a>');
                        }
                        else if ($("#type").val() == "Auditing" || row.Status == '待付款' || row.Status == '待审核' || row.Status == '待确认') {
                            html.push('<a href="./Auditing?id=' + id + '">审核</a>');
                        } else  {
                            html.push('<a href="./Details?id=' + id + '">查看</a>');
                            if (row.Status != '被拒绝') {
                                html.push('<a href="./Edit?id=' + id + '">编辑</a>');
                            }
                            if (row.IsSelf.toString() == 'false' && row.Status != '被拒绝') {
                                //html.push('<a onclick="deleteShopEvent(' + id + ');">删除</a>');
                                html.push('<a href="./BusinessCategory?id=' + id + '">经营类目</a>');
                            }
                        }
                        html.push("</span>");

                        return html.join("");
                    }
                }
            ]]
        });

    };

    $(function () {

        Query();
        $("#searchBtn").click(function (e) {
            Query();
            searchClose(e);
        });
    });

</script>

<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>店铺</strong>
        @if (((string)ViewBag.Type).Equals("Auditing"))
        {
            <li class="active"><a>开店审核</a></li>
            <li><a href="./Management">管理</a></li>
        }
        else
        {
            <li><a href="./Management?type=Auditing">开店审核</a></li>
            <li class="active"><a>管理</a></li>
        }
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>1、</span><p>商家入驻需提交申请，管理员根据商家填写的信息进行审核并设置类目及分佣比例</p>
                <span>2、</span><p>管理平台所有店铺，审核商家入店申请，可设置类目及分佣比例</p>
            </div>
        </em>
    </ul>
    <div id="shopToolBar">
        <div class="search-box only-line">
            <form class="custom-inline" role="form">
                <div class="form-group">
                    <label class="label-inline" for="">店铺名称</label>
                    <input class="form-control input-ssm" type="text" id="shopName">
                </div>
                @*<div class="form-group">
                    <label class="label-inline" for="">店铺账号</label>
                    <input class="form-control input-ssm" type="text" id="shopAccount">
                </div>*@
                <div class="form-group">
                    <label class="label-inline" for="">店铺等级</label>
                    @Html.DropDownListFor(s => s.ShopGrade, ((IEnumerable<SelectListItem>)ViewBag.Grade),
                             new { @class = "form-control input-ssm", id = "shopGradeId" })
                </div>
                <div class="form-group">
                    <label class="label-inline" for="">店铺状态</label>
                    @Html.DropDownListFor(s => s.Status, ((IEnumerable<SelectListItem>)ViewBag.Status),
                    new { @class = "form-control input-ssm", id = "shopStatus" })

                </div>
                <input type="button" class="btn btn-primary btn-sm" id="searchBtn" value="搜 索">
            </form>
        </div>
    </div>
    <table class="table mt20" id="shopDatagrid"></table>
    <input type="hidden" value="@ViewBag.Type" id="type" />
</div>
